﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Xceed.Silverlight.Data;

namespace Xceed.Silverlight.ListBox
{
  internal static class PanelUtils
  {

    public static int CompareDataPaths( DataPath firstDataPath, DataPath secondDataPath )
    {
      //This method will return 0 if the two node paths are equivalent 
      //This method will return a negative number that indicates how much the first node path needs to be unwinded to get to a common root with the second node path
      //This method will return a positive number if the second node path is longer (and root are equivalents).

      if( firstDataPath == null || firstDataPath.Depth == 0 )
        return 0;

      if( secondDataPath == null || secondDataPath.Depth == 0 )
        return -firstDataPath.Depth;

      int dataPathLength = firstDataPath.Depth;
      int maxValue = secondDataPath.Depth - 1;
      int matchCounter = 0;

      while( matchCounter != dataPathLength )
      {
        if( !firstDataPath[ matchCounter ].Equals( secondDataPath[ matchCounter ] ) )
          return matchCounter - dataPathLength;

        matchCounter++;
      }

      return maxValue - matchCounter;
    }

    public static ListBoxContainerConfigurationBase GetContainerConfigurationFromDataPath( DataPath dataPath,
                                                                                           ListBoxContainerConfigurationBase itemConfiguration,
                                                                                           ListBoxContainerConfigurationBase groupHeaderConfiguration )
    {
      if( dataPath == null )
        throw new ArgumentNullException( "dataPath shouldn't be null here.", "dataPath" );

      if( dataPath.LastChild is GroupDataItem )
      {
        return groupHeaderConfiguration;
      }
      else
      {
        return itemConfiguration;
      }

    }


  }
}
